﻿#region License Information

/* •——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————•
   | Copyright Aptillon, Inc.                                                                                        |
   | This file is part of the CKS:API project - cksapi.codeplex.com                                                       |
   | Usage, modification and distribution subject to the license terms available here: http://cksapi.codeplex.com/license |
   |                                                                                                                      |
   | Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,             |
   | either express or implied.                                                                                           |
   |                                                                                                                      |
   | THIS MESSAGE MAY NOT BE LEGALLY REMOVED                                                                              |
   •——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————• */

#endregion

using System;
using System.Collections.Generic;
using Microsoft.SharePoint.Administration;
using System.Runtime.InteropServices;
using CKS.API.Logging;
using CKS.API;

namespace CKS.API.Logging
{
    [Guid("3D517FFA-D20B-46A8-9553-DABFDF77253D")]
    public class CKSFarmLoggingService : SPDiagnosticsServiceBase
    {



        #region Constructors



        public CKSFarmLoggingService()
            : base(Constants.CKSAPILoggingServiceName, SPFarm.Local)
        { }



        #endregion

        #region Properties

        public static string AreaName
        {
            get
            {
                return Constants.CKSAPIAreaName;
            }

        }



        public static string LoggingServiceName
        {
            get
            {
                return Constants.CKSAPILoggingServiceName;
            }

        }

        #endregion

        #region Public Methods

        public static CKSFarmLoggingService Local
        {
            get
            {
                return SPFarm.Local.Services.GetValue<CKSFarmLoggingService>(LoggingServiceName);

            }
        }

        #endregion

        #region Protected Methods

        protected override IEnumerable<SPDiagnosticsArea> ProvideAreas()
        {
            List<SPDiagnosticsArea> areaList = new List<SPDiagnosticsArea>();
            List<SPDiagnosticsCategory> categoryList = new List<SPDiagnosticsCategory>();
            TraceSeverity defaultTraceSeverity = TraceSeverity.Medium;
            EventSeverity defaultEventSeverity = EventSeverity.Error;

            Array.ForEach(Enum.GetNames(typeof(CKSLoggingCategory)), catName =>
            {
                int categoryId = (int)Enum.Parse(typeof(CKSLoggingCategory), catName);
                categoryList.Add(new SPDiagnosticsCategory(catName, defaultTraceSeverity, defaultEventSeverity, 0, (uint)categoryId));
            });

            areaList.Add(new SPDiagnosticsArea(AreaName, 0, 0, false, categoryList));
            return areaList;


        }

        #endregion

    }
}
